package com.wjh.yygh.user.api;

import com.wjh.yygh.common.result.Result;
import com.wjh.yygh.model.user.UserInfo;
import com.wjh.yygh.user.service.UserInfoService;
import com.wjh.yygh.utils.AuthContextHolder;
import com.wjh.yygh.vo.user.LoginVo;
import com.wjh.yygh.vo.user.UserAuthVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/user")
@Api(tags = "用户管理")
public class UserInfoApiController {

    @Autowired
    private UserInfoService userInfoService;

    @PostMapping("/login")
    public Result login(@RequestBody LoginVo loginVo){
        return Result.ok(userInfoService.loginInfo(loginVo));
    }

    @ApiOperation(value = "认证")
    @PostMapping("/auth/userAuth")
    public Result userAuth(@RequestBody UserAuthVo userAuthVo, HttpServletRequest request){
        userInfoService.userAuth(AuthContextHolder.getUserId(request),userAuthVo);
        return Result.ok();
    }

    @ApiOperation(value = "获取登录用户信息")
    @PostMapping("/auth/getUserInfo")
    public Result getUserInfo(HttpServletRequest request){
        Long userId = AuthContextHolder.getUserId(request);
        UserInfo byId = userInfoService.getById(userId);
        return Result.ok(byId);
    }





}
